package com.sanhe.roller.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

import com.sanhe.roller.R;

public class SelectionAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context mContext;
    private final int PLACEHOLDER_CODE = -1;
    private int placeholder_width;
    private int center_index, last_index;

    public SelectionAdapter(Context mContext) {
        this.mContext = mContext;
        placeholder_width = 200;
        center_index = 1;
        last_index = 1;
    }

    /***
     * 正常一屏显示的个数
     * @return
     */
    public int getMeaSureItemCount() {
        return 3;
    }

    /***
     * 设置中心
     * @param index
     */
    public void setCenter_index(int index) {
        if (index == center_index)
            return;
        last_index = center_index;
        center_index = index;
        notifyItemChanged(last_index);
        notifyItemChanged(center_index);
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType == PLACEHOLDER_CODE) {
            View view = new View(mContext);
            int view_width = parent.getMeasuredWidth() / 2 - placeholder_width / 2;
            RecyclerView.LayoutParams params = new RecyclerView.LayoutParams(view_width, RecyclerView.LayoutParams.WRAP_CONTENT);
            view.setLayoutParams(params);
            PlaceHolderViewHolder holder = new PlaceHolderViewHolder(view);
            return holder;
        }
        View view = LayoutInflater.from(mContext).inflate(R.layout.selection_item, parent, false);
        UnionViewHolder viewHolder = new UnionViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof UnionViewHolder) {

        }
    }

    @Override
    public int getItemCount() {
        return 4 + 2;
    }

    @Override
    public int getItemViewType(int position) {
        if (position == 0 || position == getItemCount() - 1) {
            return PLACEHOLDER_CODE;
        }
        return super.getItemViewType(position);
    }

    class UnionViewHolder extends RecyclerView.ViewHolder {

        public UnionViewHolder(View itemView) {
            super(itemView);
        }
    }

    class PlaceHolderViewHolder extends RecyclerView.ViewHolder {

        public PlaceHolderViewHolder(View itemView) {
            super(itemView);
        }
    }

}
